package com.example.echoewish.ui.main_activity;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.echoewish.pojo.PartPost;
import com.example.echoewish.R;


import java.util.List;

public class PartPostAdapter extends ArrayAdapter<PartPost> {
    private Context context=null;
    private int resourceId;

    public PartPostAdapter(@NonNull Context context, int resource, @NonNull List<PartPost> objects) {
        super(context, resource, objects);
        this.context=context;
        this.resourceId=resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view= LayoutInflater.from(context).inflate(resourceId,parent,false);
        PartPost partPost=(PartPost)getItem(position);
        TextView titleTextView=view.findViewById(R.id.part_post_title_textview);
        TextView contentTextView=view.findViewById(R.id.part_post_content_textview);
        if(partPost!=null)
        {
            titleTextView.setText(partPost.title);
            contentTextView.setText(partPost.content);
        }
        return view;
    }
}
